package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.common.R;
import com.itheima.entity.Orders;
import com.itheima.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;


    /**
     * 用户下单
     *
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders) {
        log.info("订单数据:{}", orders);
        orderService.sumbit(orders);
        return R.success("下单成功!");
    }


    /**
     * 订单查询
     *
     * @param page
     * @param pageSize
     * @param number
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/page")
    public R<Page> orderDetail(int page, int pageSize, String number, String startTime, String endTime) {
        log.info("分页信息:{}", page);
        Page orderDetail = orderService.orderDetail(page, pageSize, number, startTime, endTime);
        return R.success(orderDetail);
    }


    /**
     * 手机端订单查询
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/userPage")
    public R<Page> userPage(int page, int pageSize) {
        Orders orders = new Orders();
        String number = orders.getNumber();

        Page orderPage = orderService.orderPage(page, pageSize, number);

        return R.success(orderPage);
    }


}
